# 添加用户
useradd admin:   
  cmd.run:
  - unless: id admin

# 修改密碼
echo "R00T000" |passwd --stdin super:
  cmd.run:
  - onlyif: id admin  




# 添加sudoer 账号
super-user-group:
  group.present:
    - name: super
    - gid: 1008
    - unless: grep -o super /etc/group
  user.present:
    - name: super
    - fullname: super
    - shell: /bin/bash
    - uid: 1008
    - gid: 1008
    - groups:
      - super
      - root
    - password: 'super@888'
    - unless: grep -o super /etc/passwd

salt-ssh-key:
  file.directory:
    - name: /home/super/.ssh
    - mode: 700
    - user: super
    - group: super

  ssh_auth.present:
    - user: super
    - name: /home/super/.ssh/authorized_keys
    - source: salt://init/files/super.pub
    - mode: 600
    - user: super
    - group: super
    - require:
      - user: super-user-group

{% if salt['file.file_exists']('/etc/sudoers') %}
/etc/sudoers:
  file.append:
    - text:
      - super ALL=(ALL) NOPASSWD:ALL
      - Defaults:super !requiretty
    - unless: grep -o super /etc/sudoers
{% endif %}
